﻿using B.S.BasicData.Api.Read.Applications.Commands.Accounts;
using B.S.BasicData.Api.Read.Dtos;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    /// <summary>
    /// API控制器-读
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public ManagementController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 全局异常过滤器测试方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet("Text")]
        public IActionResult Text()
        {
            int num = int.Parse("asvc");
            return Ok(num);

        }


        /// <summary>
        /// 登录 
        /// </summary>
        /// <param name="command">登录参数</param>
        /// <returns>返回任务</returns>
        [HttpPost("Login")]
        public Task<ApiResult<LoginDto>> Login(LoginQueryCommand command)
        {
            try
            {
                return mediator.Send(command);    
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 查询 
        /// </summary>
        /// <param name="command">查询参数</param>
        /// <returns>返回任务</returns>
        [HttpGet("GetUser")]
        public Task<ApiResult<ApiPaging<ShowDto>>> GetUser([FromQuery]GetUserQueryCommand command)
        {
            try
            {
                return mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 查询日志
        /// </summary>
        /// <param name="command">查询日志参数</param>
        /// <returns>返回任务</returns>
        [HttpGet("GetNlog")]
        public Task<ApiResult<ApiPaging<NlogInfo>>> GetNlog([FromQuery] NlogQueryCommand command)
        {
            try
            {
                return mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }

        }



        /// <summary>
        /// 查询 树形
        /// </summary>
        /// <param name="command">查询参数</param>
        /// <returns>返回任务</returns>
        [HttpGet("GetTree")]
        public Task<ApiResult<List<DeptmentDto>>> GetTree()
        {
            try
            {
                DeptQueryCommand command = new DeptQueryCommand();
                return mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }

        }

    }
}
